package com.ctosb.classviewer.clazz.command;

/**
 * 操作指令基类
 * @Author alan
 * @Date 2020/12/22 11:32 下午
 */
public abstract class BaseCommand {

    private short operationCode;

    public BaseCommand(short operationCode) {
        if (!checkOperationCode(operationCode)) {
            processIfCheckFail(operationCode);
        }
        this.operationCode = operationCode;
    }

    /**
     * 检查操作码
     * @Author alan
     * @Date 2020/12/30 11:48 下午
     * @param operationCode
     * @return
     */
    protected boolean checkOperationCode(short operationCode) {
        return true;
    }

    /**
     * 检查失败后处理
     * @Author alan
     * @Date 2020/12/30 11:48 下午
     * @param operationCode
     * @return
     */
    protected void processIfCheckFail(short operationCode) {
        throw new UnsupportedOperationException(String.format("%s only support operationCode %d.", getClass().getSimpleName(), operationCode));
    }


    public short getOperationCode() {
        return operationCode;
    }
}
